
/* ----------------------- Platform includes --------------------------------*/
#include "mbcrc.h"

USHORT GetCrc16(UCHAR *pucBuffer,USHORT wDataLength)
{
    UCHAR ucHigh,ucLow,ucCrc16H,ucCrc16L;
    UCHAR ucSaveH,ucSaveL;
    int ii,ij;
    ucCrc16H=0xFF;
    ucCrc16L=0xFF;
    ucLow=0x1;
    ucHigh=0xA0;
    for (ii=0;ii<wDataLength;ii++)
    {
       ucCrc16L=(ucCrc16L ^ pucBuffer[ii]);
       for (ij=0;ij<8;ij++)
       {
           ucSaveH=ucCrc16H;
           ucSaveL=ucCrc16L;
           ucCrc16H=(ucCrc16H>>1);
           ucCrc16L=(ucCrc16L>>1);
           if ((ucSaveH & 0x01)==0x01)
           {
              ucCrc16L=(ucCrc16L | 0x80);
           }
           if ((ucSaveL & 0x01)==0x01)
           {
              ucCrc16H = (ucCrc16H ^ ucHigh);
              ucCrc16L = (ucCrc16L ^ ucLow);
           }         
       }
    }

     return(ucCrc16L + (ucCrc16H<<8)) ;
}
